
********************************************************************************************************************************
						
														***Marlene Mauk, Max Groemping***
			***Online Disinformation Predicts Inaccurate Beliefs about Election Fairness among Winners and Losers***
												***Replication File  ##7 - ROBUSTNESS CHECKS***
						
********************************************************************************************************************************


*************************************************************
	*Robustness Checks G1 - alternative measurement of DV*
*************************************************************

* create Figure G1.1
graph set window fontface "Times New Roman"
set tracedepth 1
set trace on
foreach x in rc1a_model2 rc1b_model2 rc1c_model2 rc1d_model2 rc1e_model2 {
	clear all
	import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\\`x'.dat", delimiter(tab, collapse) varnames(nonames)
	destring xaxis pei1 pei1_low pei1_high, force replace
	twoway ///
	(line pei1 xaxis, lp(solid) lc(gs1)) ///
	(line pei1_low xaxis, lp(dash) lc(gs6)) ///
	(line pei1_high xaxis, lp(dash) lc(gs6)), ///
	graphregion(color(white)) legend(region(lp(blank))) ///
	ytitle("effects of electoral integrity on perceptions of fairness", size(small)) yline(0) ///
	xtitle("online disinformation") xlabel(0(0.1)1) ///
	legend(off)
	graph save `x', replace
}
graph combine rc1a_model2.gph, title(votes being counted fairly) name(plot1, replace) graphregion(color(white))
graph combine rc1b_model2.gph, title(opposition (not) prevented from running) name(plot2, replace) graphregion(color(white))
graph combine rc1c_model2.gph, title(election officials fair) name(plot3, replace) graphregion(color(white))
graph combine rc1d_model2.gph, title(rich people (not) buying elections) name(plot4, replace) graphregion(color(white))
graph combine rc1e_model2.gph, title((no) violence at polls) name(plot5, replace) graphregion(color(white))
graph combine plot1 plot2 plot3 plot4 plot5, graphregion(color(white)) rows(2) ysize(5) xsize(10)
graph export .\figures\figureg1_1.png, replace
 
* create Figure G1.2
foreach x in rc1a_model3 rc1b_model3 rc1c_model3 rc1d_model3 rc1e_model3 {
	clear all
	import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\\`x'.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1 pei1_low pei1_high, force replace
	twoway ///
	(line pei1 xaxis, lp(solid) lc(gs1)) ///
	(line pei1_low xaxis, lp(dash) lc(gs6)) ///
	(line pei1_high xaxis, lp(dash) lc(gs6)), ///
	graphregion(color(white)) legend(region(lp(blank))) ///
	ytitle("effects of winner status on perceptions of fairness", size(small)) yline(0) ///
	xtitle("online disinformation") xlabel(0(0.1)1) ///
	legend(off)
	graph save `x', replace
}
graph combine rc1a_model3.gph, title(votes being counted fairly) name(plot1, replace) graphregion(color(white))
graph combine rc1b_model3.gph, title(opposition (not) prevented from running) name(plot2, replace) graphregion(color(white))
graph combine rc1c_model3.gph, title(election officials fair) name(plot3, replace) graphregion(color(white))
graph combine rc1d_model3.gph, title(rich people (not) buying elections) name(plot4, replace) graphregion(color(white))
graph combine rc1e_model3.gph, title((no) violence at polls) name(plot5, replace) graphregion(color(white))
graph combine plot1 plot2 plot3 plot4 plot5, graphregion(color(white)) rows(2) ysize(5) xsize(10)
graph export .\figures\figureg1_2.png, replace

* create Figure G1.3
foreach x in rc1a_model4 rc1b_model4 rc1c_model4 rc1d_model4 rc1e_model4 {
	clear all
	import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\\`x'_winners.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1 pei1_low pei1_high, force replace
	save `x'_high.dta, replace
	clear
	import delimited xaxis pei1alt pei1alt_low pei1alt_high using ".\mplus\\`x'_losers.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1alt pei1alt_low pei1alt_high, force replace
	gen yline = 0
	save `x'_low.dta, replace
	append using `x'_high.dta
	twoway ///
	(pci 0 0 0 1, lc(cranberry)) ///
	(line yline xaxis, lp(solid) lc(cranberry) lwidth(0.1)) ///
	(line pei1 xaxis, lp(solid) lc(black)) ///
	(line pei1_high xaxis, lp(solid) lc(black) lwidth(0.1)) ///
	(line pei1_low xaxis, lp(solid) lc(black) lwidth(0.1)) ///
	(line pei1alt_high xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
	(line pei1alt_low xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
	(line pei1alt xaxis, lp(dash) lc(gs9)), ///
	graphregion(color(white)) legend(region(lp(blank))) ///	
	ytitle("effects of electoral integrity on public perceptions of fairness", size(small)) yline(0) ///
	xtitle("online disinformation, for winners (solid line) and losers (dashed line)", size(small)) xlabel(0(0.1)1) ///
	legend(off)
	graph save `x'_winnerloser, replace
}
graph combine rc1a_model4_winnerloser.gph, title(votes being counted fairly) name(plot1, replace) graphregion(color(white))
graph combine rc1b_model4_winnerloser.gph, title(opposition (not) prevented from running) name(plot2, replace) graphregion(color(white))
graph combine rc1c_model4_winnerloser.gph, title(election officials fair) name(plot3, replace) graphregion(color(white))
graph combine rc1d_model4_winnerloser.gph, title(rich people (not) buying elections) name(plot4, replace) graphregion(color(white))
graph combine rc1e_model4_winnerloser.gph, title((no) violence at polls) name(plot5, replace) graphregion(color(white))
graph combine plot1 plot2 plot3 plot4 plot5, graphregion(color(white)) rows(2) ysize(5) xsize(10)
graph export .\figures\figureg1_3.png, replace



*****************************************************************************
	*Robustness Checks G2 - alternative measurement of de facto integrity*
*****************************************************************************

* create Figure G2.1
graph set window fontface "Times New Roman"
foreach x in rc2a_model2 rc2b_model2 rc2c_model2 {
	clear all
	import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\\`x'.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1 pei1_low pei1_high, force replace
	twoway ///
	(line pei1 xaxis, lp(solid) lc(gs1)) ///
	(line pei1_low xaxis, lp(dash) lc(gs6)) ///
	(line pei1_high xaxis, lp(dash) lc(gs6)), ///
	graphregion(color(white)) legend(region(lp(blank))) ///
	ytitle("effects of electoral integrity on perceptions of fairness", size(medsmall)) yline(0) ///
	xtitle("online disinformation") xlabel(0(0.1)1) ///
	legend(off)
	graph save `x', replace
}
graph combine rc2a_model2.gph, title(PEI expert-level data) name(plot1, replace) graphregion(color(white))
graph combine rc2b_model2.gph, title(NELDA data) name(plot2, replace) graphregion(color(white))
graph combine rc2c_model2.gph, title(V-Dem data) name(plot3, replace) graphregion(color(white))
graph combine plot1 plot2 plot3, graphregion(color(white)) rows(1) ysize(2) xsize(6)
graph export .\figures\figureg2_1.png, replace

* create Figure G2.2
foreach x in rc2a_model3 rc2b_model3 rc2c_model3 {
	clear all
	import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\\`x'.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1 pei1_low pei1_high, force replace
	twoway ///
	(line pei1 xaxis, lp(solid) lc(gs1)) ///
	(line pei1_low xaxis, lp(dash) lc(gs6)) ///
	(line pei1_high xaxis, lp(dash) lc(gs6)), ///
	graphregion(color(white)) legend(region(lp(blank))) ///
	ytitle("effects of winner status on perceptions of fairness", size(medsmall)) yline(0) ///
	xtitle("online disinformation") xlabel(0(0.1)1) ///
	legend(off)
	graph save `x', replace
}
graph combine rc2a_model3.gph, title(PEI expert-level data) name(plot1, replace) graphregion(color(white))
graph combine rc2b_model3.gph, title(NELDA data) name(plot2, replace) graphregion(color(white))
graph combine rc2c_model3.gph, title(V-Dem data) name(plot3, replace) graphregion(color(white))
graph combine plot1 plot2 plot3, graphregion(color(white)) rows(1) ysize(2) xsize(6)
graph export .\figures\figureg2_2.png, replace

* create Figure G2.3
foreach x in rc2a_model4 rc2b_model4 rc2c_model4 {
	clear all
	import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\\`x'_winners.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1 pei1_low pei1_high, force replace
	save `x'_high.dta, replace
	clear
	import delimited xaxis pei1alt pei1alt_low pei1alt_high using ".\mplus\\`x'_losers.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1alt pei1alt_low pei1alt_high, force replace
	gen yline = 0
	save `x'_low.dta, replace
	append using `x'_high.dta
	twoway ///
	(pci 0 0 0 1, lc(cranberry)) ///
	(line yline xaxis, lp(solid) lc(cranberry) lwidth(0.1)) ///
	(line pei1 xaxis, lp(solid) lc(black)) ///
	(line pei1_high xaxis, lp(solid) lc(black) lwidth(0.1)) ///
	(line pei1_low xaxis, lp(solid) lc(black) lwidth(0.1)) ///
	(line pei1alt_high xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
	(line pei1alt_low xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
	(line pei1alt xaxis, lp(dash) lc(gs9)), ///
	graphregion(color(white)) legend(region(lp(blank))) ///	
	ytitle("effects of electoral integrity on public perceptions of fairness", size(medsmall)) yline(0) ///
	xtitle("online disinformation, for winners (solid line) and losers (dashed line)", size(medsmall)) xlabel(0(0.1)1) ///
	legend(off)
	graph save `x'_winnerloser, replace
}
graph combine rc2a_model4_winnerloser.gph, title(PEI expert-level data) name(plot1, replace) graphregion(color(white))
graph combine rc2b_model4_winnerloser.gph, title(NELDA data) name(plot2, replace) graphregion(color(white))
graph combine rc2c_model4_winnerloser.gph, title(V-Dem data) name(plot3, replace) graphregion(color(white))
graph combine plot1 plot2 plot3 , graphregion(color(white)) rows(1) ysize(2) xsize(6)
graph export .\figures\figureg2_3.png, replace


*************************************************************************
	*Robustness Checks G3 - alternative measurement of disinformation*
*************************************************************************

* create Figure G3.1
graph set window fontface "Times New Roman"
foreach x in rc3a_model2 rc3b_model2 rc3c_model2 {
	clear all
	import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\\`x'.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1 pei1_low pei1_high, force replace
	twoway ///
	(line pei1 xaxis, lp(solid) lc(gs1)) ///
	(line pei1_low xaxis, lp(dash) lc(gs6)) ///
	(line pei1_high xaxis, lp(dash) lc(gs6)), ///
	graphregion(color(white)) legend(region(lp(blank))) ///
	ytitle("effects of electoral integrity on perceptions of fairness", size(medsmall)) yline(0) ///
	xtitle("online disinformation") xlabel(0(0.1)1) ///
	legend(off)
	graph save `x', replace
}
graph combine rc3a_model2.gph, title(government disinformation) name(plot1, replace) graphregion(color(white))
graph combine rc3b_model2.gph, title(foreign disinformation) name(plot2, replace) graphregion(color(white))
graph combine rc3c_model2.gph, title(partisan disinformation) name(plot3, replace) graphregion(color(white))
graph combine plot1 plot2 plot3, graphregion(color(white)) rows(1) ysize(2) xsize(6)
graph export .\figures\figureg3_1.png, replace

* create Figure G3.2
foreach x in rc3a_model3 rc3b_model3 rc3c_model3 {
	clear all
	import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\\`x'.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1 pei1_low pei1_high, force replace
	twoway ///
	(line pei1 xaxis, lp(solid) lc(gs1)) ///
	(line pei1_low xaxis, lp(dash) lc(gs6)) ///
	(line pei1_high xaxis, lp(dash) lc(gs6)), ///
	graphregion(color(white)) legend(region(lp(blank))) ///
	ytitle("effects of winner status on perceptions of fairness", size(medsmall)) yline(0) ///
	xtitle("online disinformation") xlabel(0(0.1)1) ///
	legend(off)
	graph save `x', replace
}
graph combine rc3a_model3.gph, title(government disinformation) name(plot1, replace) graphregion(color(white))
graph combine rc3b_model3.gph, title(foreign disinformation) name(plot2, replace) graphregion(color(white))
graph combine rc3c_model3.gph, title(partisan disinformation) name(plot3, replace) graphregion(color(white))
graph combine plot1 plot2 plot3, graphregion(color(white)) rows(1) ysize(2) xsize(6)
graph export .\figures\figureg3_2.png, replace

* create Figure G3.3
foreach x in rc3a_model4 rc3b_model4 rc3c_model4 {
	clear all
	import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\\`x'_winners.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1 pei1_low pei1_high, force replace
	save `x'_high.dta, replace
	clear
	import delimited xaxis pei1alt pei1alt_low pei1alt_high using ".\mplus\\`x'_losers.dat", delimiter(tab, collapse) varnames(nonames) 
	destring xaxis pei1alt pei1alt_low pei1alt_high, force replace
	gen yline = 0
	save `x'_low.dta, replace
	append using `x'_high.dta
	twoway ///
	(pci 0 0 0 1, lc(cranberry)) ///* adds a line from (0|0 to 1|0) = pseudo y-line that doesn't get superimposed by the plots
	(line yline xaxis, lp(solid) lc(cranberry) lwidth(0.1)) ///
	(line pei1 xaxis, lp(solid) lc(black)) ///
	(line pei1_high xaxis, lp(solid) lc(black) lwidth(0.1)) ///
	(line pei1_low xaxis, lp(solid) lc(black) lwidth(0.1)) ///
	(line pei1alt_high xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
	(line pei1alt_low xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
	(line pei1alt xaxis, lp(dash) lc(gs9)), ///
	graphregion(color(white)) legend(region(lp(blank))) ///	
	ytitle("effects of electoral integrity on public perceptions of fairness", size(medsmall)) yline(0) ///
	xtitle("online disinformation, for winners (solid line) and losers (dashed line)", size(small)) xlabel(0(0.1)1) ///
	legend(off)
	graph save `x'_winnerloser, replace
}
graph combine rc3a_model4_winnerloser.gph, title(government disinformation) name(plot1, replace) graphregion(color(white))
graph combine rc3b_model4_winnerloser.gph, title(foreign disinformation) name(plot2, replace) graphregion(color(white))
graph combine rc3c_model4_winnerloser.gph, title(partisan disinformation) name(plot3, replace) graphregion(color(white))
graph combine plot1 plot2 plot3 , graphregion(color(white)) rows(1) ysize(2) xsize(6)
graph export .\figures\figureg3_3.png, replace



******************************************************
	*Robustness Checks G4 - without winner/loser*
******************************************************

* create Figure G4
graph set window fontface "Times New Roman"
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc4_model2.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of electoral integrity on perceptions of fairness", size(small)) yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figureg4.png, replace



***********************************************************************
	*Robustness Checks G5 - without control variables*
***********************************************************************

* create Figure G5.1
graph set window fontface "Times New Roman"
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc5_model2.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of electoral integrity on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figureg5_1.png, replace 

* create Figure G5.2
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc5_model3.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of winner status on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figureg5_2.png, replace 

* create Figure G5.3
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc5_model4_winners.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
save model4_high.dta, replace
clear
import delimited xaxis pei1alt pei1alt_low pei1alt_high using ".\mplus\rc5_model4_losers.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1alt pei1alt_low pei1alt_high, force replace
gen yline = 0
save model4_low.dta, replace
append using model4_high.dta
twoway ///
(pci 0 0 0 1, lc(cranberry)) ///* adds a line from (0|0 to 1|0) = pseudo y-line that doesn't get superimposed by the plots
(line yline xaxis, lp(solid) lc(cranberry) lwidth(0.1)) ///
(line pei1 xaxis, lp(solid) lc(black)) ///
(line pei1_high xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1_low xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1alt_high xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt_low xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt xaxis, lp(dash) lc(gs9)), ///
graphregion(color(white)) legend(region(lp(blank))) ///	
ytitle("effects of electoral integrity on public perceptions of fairness", size(small)) yline(0) ///
xtitle("online disinformation, for winners (solid line) and losers (dashed line)", size(small)) xlabel(0(0.1)1) ///
graphregion(color(white)) legend(region(lp(blank))) ///
legend(off)
graph export .\figures\figureg5_3.png, replace 



********************************************************************************
	*Robustness Checks G6 - with standard errors clustered at country level*
********************************************************************************

* create Figure G6.1
graph set window fontface "Times New Roman"
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc6_model2.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of electoral integrity on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figureg6_1.png, replace 

* create Figure G6.2
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc6_model3.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of winner status on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figureg6_2.png, replace 

* create Figure G6.3
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc6_model4_winners.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
save model4_high.dta, replace
clear
import delimited xaxis pei1alt pei1alt_low pei1alt_high using ".\mplus\rc6_model4_losers.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1alt pei1alt_low pei1alt_high, force replace
gen yline = 0
save model4_low.dta, replace
append using model4_high.dta
twoway ///
(pci 0 0 0 1, lc(cranberry)) ///
(line yline xaxis, lp(solid) lc(cranberry) lwidth(0.1)) ///
(line pei1 xaxis, lp(solid) lc(black)) ///
(line pei1_high xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1_low xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1alt_high xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt_low xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt xaxis, lp(dash) lc(gs9)), ///
graphregion(color(white)) legend(region(lp(blank))) ///	
ytitle("effects of electoral integrity on public perceptions of fairness", size(small)) yline(0) ///
xtitle("online disinformation, for winners (solid line) and losers (dashed line)", size(small)) xlabel(0(0.1)1) ///
graphregion(color(white)) legend(region(lp(blank))) ///
legend(off)
graph export .\figures\figureg6_3.png, replace 



********************************************************************************
	*Robustness Checks G7 - without election monitors*
********************************************************************************

* create Figure G7.1
graph set window fontface "Times New Roman"
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc7_model2.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of electoral integrity on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off) 
graph export .\figures\figureg7_1.png, replace 

* create Figure G7.2
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc7_model3.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of winner status on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figureg7_2.png, replace 

* create Figure G7.3
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc7_model4_winners.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
save model4_high.dta, replace
clear
import delimited xaxis pei1alt pei1alt_low pei1alt_high using ".\mplus\rc7_model4_losers.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1alt pei1alt_low pei1alt_high, force replace
gen yline = 0
save model4_low.dta, replace
append using model4_high.dta
twoway ///
(pci 0 0 0 1, lc(cranberry)) ///* adds a line from (0|0 to 1|0) = pseudo y-line that doesn't get superimposed by the plots
(line yline xaxis, lp(solid) lc(cranberry) lwidth(0.1)) ///
(line pei1 xaxis, lp(solid) lc(black)) ///
(line pei1_high xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1_low xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1alt_high xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt_low xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt xaxis, lp(dash) lc(gs9)), ///
graphregion(color(white)) legend(region(lp(blank))) ///	
ytitle("effects of electoral integrity on public perceptions of fairness", size(small)) yline(0) ///
xtitle("online disinformation, for winners (solid line) and losers (dashed line)", size(small)) xlabel(0(0.1)1) ///
graphregion(color(white)) legend(region(lp(blank))) ///
legend(off)
graph export .\figures\figureg7_3.png, replace 



********************************************************************************
	*Robustness Checks G8 - testing for non-linear interaction effects*
********************************************************************************

clear
use mergeddata.dta

* run linear interaction diagnostics for moderator electoral integrity (Figure G8.1)
sort pei01
egen pei_tercile=xtile(pei01), nq(3)
graph twoway (lfit pef01 disinfo01) (scatter pef01 disinfo01) (lowess pef01 disinfo01) if pei_tercile==1, graphregion(color(white)) name(plot1, replace) xtitle("moderator D: disinformation") ytitle("outcome Y: perceptions of electoral fairness") title("X: de facto integrity=low", size(medium))
graph twoway (lfit pef01 disinfo01) (scatter pef01 disinfo01) (lowess pef01 disinfo01) if pei_tercile==2, graphregion(color(white)) name(plot2, replace) xtitle("moderator D: disinformation") ytitle("outcome Y: perceptions of electoral fairness") title("X: de facto integrity=medium", size(medium))
graph twoway (lfit pef01 disinfo01) (scatter pef01 disinfo01) (lowess pef01 disinfo01) if pei_tercile==3, graphregion(color(white)) name(plot3, replace) xtitle("moderator D: disinformation") ytitle("outcome Y: perceptions of electoral fairness") title("X: de facto integrity=high", size(medium))
graph combine plot1 plot2 plot3, rows(2) graphregion(color(white))
graph export .\figures\figureg8_1.png, replace

* run nonlinear interaction effect for moderator electoral integrity (Figure G8.2)
interflex pef01 pei01 disinfo01 polint soctrust satdem income age edu_2 edu_3 v2xme_altinf gdpgrowth internet v2eltrnout v2elaccept democracy, type(binning) n(3) vce(robust) ylab(percetions of electoral integrity) dlab(de facto electoral integrity) xlab(online disinformation) xd(density) ti(binning approach)
graph save plot1.gph, replace
interflex pef01 pei01 disinfo01 polint soctrust satdem income age edu_2 edu_3 v2xme_altinf gdpgrowth internet v2eltrnout v2elaccept democracy, type(kernel) vce(robust) ylab(percetions of electoral integrity) dlab(de facto electoral integrity) xlab(online disinformation) xd(density) ti(kernel approach)
graph save plot2.gph, replace
graph combine plot1.gph plot2.gph, rows(1) graphregion(color(white))
graph export .\figures\figureg8_2.png, replace

* run linear interaction diagnostics for moderator winner/loser (Figure G8.3)
graph twoway (lfit pef01 disinfo01) (scatter pef01 disinfo01) (lowess pef01 disinfo01) if winner==1, graphregion(color(white)) name(plot1, replace) xtitle("moderator D: disinformation") ytitle("outcome Y: perceptions of electoral fairness") title("X: winner=1", size(medium))
graph twoway (lfit pef01 disinfo01) (scatter pef01 disinfo01) (lowess pef01 disinfo01) if winner==0, graphregion(color(white)) name(plot2, replace) xtitle("moderator D: disinformation") ytitle("outcome Y: perceptions of electoral fairness") title("X: winner=0", size(medium))
graph combine plot1 plot2, rows(1) graphregion(color(white))
graph export .\figures\figureg8_3.png, replace

* run nonlinear interaction effect for moderator winner/loser (Figure G8.4)
interflex pef01 winner disinfo01 polint soctrust satdem income age edu_2 edu_3 v2xme_altinf gdpgrowth internet v2eltrnout v2elaccept democracy, type(binning) n(3) vce(robust) ylab(percetions of electoral integrity) dlab(winner/loser status) xlab(online disinformation) xd(density) ti(binning approach)
graph save plot1.gph, replace
interflex pef01 winner disinfo01 polint soctrust satdem income age edu_2 edu_3 v2xme_altinf gdpgrowth internet v2eltrnout v2elaccept democracy, type(kernel) vce(robust) ylab(percetions of electoral integrity) dlab(winner/loser status) xlab(online disinformation) xd(density) ti(kernel approach)
graph save plot2.gph, replace
graph combine plot1.gph plot2.gph, rows(1) graphregion(color(white))
graph export .\figures\figureg8_4.png, replace



***********************************************************************
	*Robustness Checks G9 - excluding countries that held elections*
***********************************************************************

* create Figure G9.1
graph set window fontface "Times New Roman"
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc9_model2.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of electoral integrity on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off) name(plot1, replace)
graph export .\figures\figureg9_1.png, replace 

* create Figure G9.2
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc9_model3.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of winner status on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off) name(plot1, replace)
graph export .\figures\figureg9_2.png, replace 

* create Figure G9.3
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc9_model4_winners.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
save model4_high.dta, replace
clear
import delimited xaxis pei1alt pei1alt_low pei1alt_high using ".\mplus\rc9_model4_losers.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1alt pei1alt_low pei1alt_high, force replace
gen yline = 0
save model4_low.dta, replace
append using model4_high.dta
twoway ///
(pci 0 0 0 1, lc(cranberry)) ///
(line yline xaxis, lp(solid) lc(cranberry) lwidth(0.1)) ///
(line pei1 xaxis, lp(solid) lc(black)) ///
(line pei1_high xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1_low xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1alt_high xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt_low xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt xaxis, lp(dash) lc(gs9)), ///
graphregion(color(white)) legend(region(lp(blank))) ///	
ytitle("effects of electoral integrity on public perceptions of fairness", size(small)) yline(0) ///
xtitle("online disinformation, for winners (solid line) and losers (dashed line)", size(small)) xlabel(0(0.1)1) ///
graphregion(color(white)) legend(region(lp(blank))) ///
legend(off) name(plot1, replace)
graph export .\figures\figureg9_3.png, replace 



********************************************************************************
	*Robustness Checks G10 - excluding countries with low internet penetration*
********************************************************************************

* create Figure G10.1
graph set window fontface "Times New Roman"
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc10_model2.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of electoral integrity on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off) 
graph export .\figures\figureg10_1.png, replace 

* create Figure G10.2
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc10_model3.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
twoway ///
(line pei1 xaxis, lp(solid) lc(gs1)) ///
(line pei1_low xaxis, lp(dash) lc(gs6)) ///
(line pei1_high xaxis, lp(dash) lc(gs6)), ///
graphregion(color(white)) legend(region(lp(blank))) ///
ytitle("effects of winner status on perceptions of fairness") yline(0) ///
xtitle("online disinformation") xlabel(0(0.1)1) ///
legend(off)
graph export .\figures\figureg10_2.png, replace 

* create Figure G10.3
clear all
import delimited xaxis pei1 pei1_low pei1_high using ".\mplus\rc10_model4_winners.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1 pei1_low pei1_high, force replace
save model4_high.dta, replace
clear
import delimited xaxis pei1alt pei1alt_low pei1alt_high using ".\mplus\rc10_model4_losers.dat", delimiter(tab, collapse) varnames(nonames) 
destring xaxis pei1alt pei1alt_low pei1alt_high, force replace
gen yline = 0
save model4_low.dta, replace
append using model4_high.dta
twoway ///
(pci 0 0 0 1, lc(cranberry)) ///
(line yline xaxis, lp(solid) lc(cranberry) lwidth(0.1)) ///
(line pei1 xaxis, lp(solid) lc(black)) ///
(line pei1_high xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1_low xaxis, lp(solid) lc(black) lwidth(0.1)) ///
(line pei1alt_high xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt_low xaxis, lp(dash) lc(gs9) lwidth(0.1)) ///
(line pei1alt xaxis, lp(dash) lc(gs9)), ///
graphregion(color(white)) legend(region(lp(blank))) ///	
ytitle("effects of electoral integrity on public perceptions of fairness", size(small)) yline(0) ///
xtitle("online disinformation, for winners (solid line) and losers (dashed line)", size(small)) xlabel(0(0.1)1) ///
graphregion(color(white)) legend(region(lp(blank))) ///
legend(off)
graph export .\figures\figureg10_3.png, replace 



********************************************************
	*Robustness Checks G11 - Political fear effects*
********************************************************

clear
use mergeddata.dta
gen nonresponse1 = .
gen nonresponse2 = .
gen nonresponse3 = .
gen nonresponse4 = .
gen nonresponse5 = .
gen nonresponse6 = .
replace nonresponse1 = 1 if pef1==.
replace nonresponse1 = 0 if pef1!=.
replace nonresponse2 = 1 if pef2==.
replace nonresponse2 = 0 if pef2!=.
replace nonresponse3 = 1 if pef6==.
replace nonresponse3 = 0 if pef6!=.
replace nonresponse4 = 1 if pef7==.
replace nonresponse4 = 0 if pef7!=.
replace nonresponse5 = 1 if pef8==.
replace nonresponse5 = 0 if pef8!=.
replace nonresponse6 = 1 if winner==.
replace nonresponse6 = 0 if winner!=.
collapse nonresponse* v2x_libdem democracy, by(elecow)

* correlation of nonresponse and (lack of) repression
corr v2x_libdem nonresponse*
corr v2x_libdem nonresponse* if democracy==1
corr v2x_libdem nonresponse* if democracy==0

* comparing nonresponse rates in democracies and autocracies (Table G11)
mean nonresponse*, over(democracy)
clear